home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
formats
/
_image.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
6KB
|
213 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
class ImageContainer(object):
'''Mixin/Interface for AudioFile to support basic embedded image editing'''
def get_primary_image(self):
'''Returns the primary embedded image or None.'''
pass
def get_images(self):
'''Returns a list of embedded images, primary first'''
image = self.get_primary_image()
if image:
return [
image]
def has_images(self):
'''Fast way to check for images, might be False if the file
was modified externally.
'''
return '~picture' in self
has_images = property(has_images)
def has_images(self, value):
if value:
self['~picture'] = 'y'
else:
self.pop('~picture', None)
has_images = has_images.setter(has_images)
def can_change_images(self):
'''Return True IFF `clear_images()` and `set_images()` are
implemented'''
return False
can_change_images = property(can_change_images)
def clear_images(self):
'''Delete all embedded images'''
raise NotImplementedError
def set_image(self, image):
'''Replaces all embedded images by the passed image.
The image type recorded in the file will be APICType.COVER_FRONT,
disregarding image.type.
'''
raise NotImplementedError
class APICType(object):
'''Enumeration of image types defined by the ID3 standard but also reused
in WMA/FLAC/VorbisComment
'''
OTHER = 0
FILE_ICON = 1
OTHER_FILE_ICON = 2
COVER_FRONT = 3
COVER_BACK = 4
LEAFLET_PAGE = 5
MEDIA = 6
LEAD_ARTIST = 7
ARTIST = 8
CONDUCTOR = 9
BAND = 10
COMPOSER = 11
LYRISCIST = 12
RECORDING_LOCATION = 13
DURING_RECORDING = 14
DURING_PERFORMANCE = 15
SCREEN_CAPTURE = 16
FISH = 17
ILLUSTRATION = 18
BAND_LOGOTYPE = 19
PUBLISHER_LOGOTYPE = 20
def to_string(cls, value):
for k, v in cls.__dict__.items():
if v == value:
return k
return ''
to_string = classmethod(to_string)
def is_valid(cls, value):
if value <= value:
return value <= cls.PUBLISHER_LOGOTYPE
value <= value
return value
is_valid = classmethod(is_valid)
def sort_key(cls, value):
'''Sorts picture types, most important picture is the lowest.
Important is defined as most representative of an album release, ymmv.
'''
important = [
cls.LEAFLET_PAGE,
cls.MEDIA,
cls.COVER_BACK,
cls.COVER_FRONT]
try:
return -important.index(value)
except ValueError:
if value < cls.COVER_FRONT:
return 100 - value
return None
sort_key = classmethod(sort_key)
class EmbeddedImage(object):
'''Embedded image, contains most of the properties needed
for FLAC and ID3 images.
'''
def __init__(self, fileobj, mime_type, width = -1, height = -1, color_depth = -1, type_ = APICType.OTHER):
self.mime_type = mime_type
self.width = width
self.height = height
self.color_depth = color_depth
self.file = fileobj
self.type = type_
def __repr__(self):
return '<%s mime_type=%r width=%d height=%d type=%s file=%r>' % (type(self).__name__, self.mime_type, self.width, self.height, APICType.to_string(self.type), self.file)
def sort_key(self):
return APICType.sort_key(self.type)
sort_key = property(sort_key)
def extensions(self):
'''A possibly empty list of extensions e.g. ["jpeg", jpg"]'''
GdkPixbuf = GdkPixbuf
import gi.repository
for format_ in GdkPixbuf.Pixbuf.get_formats():
if self.mime_type in format_.get_mime_types():
return format_.get_extensions()
return []
extensions = property(extensions)
def from_path(cls, path):
'''Reads the header of `path` and creates a new image instance
or None.
'''
GdkPixbuf = GdkPixbuf
GLib = GLib
import gi.repository
pb = []
def area_prepared(loader):
pb.append(loader.get_pixbuf())
loader = GdkPixbuf.PixbufLoader()
loader.connect('area-prepared', area_prepared)
try:
with open(path, 'rb') as h:
while not pb:
data = h.read(1024)
if data:
loader.write(data)
continue
break
except (EnvironmentError, GLib.GError):
(None,)
(None,)
return None
finally:
try:
loader.close()
except GLib.GError:
(None,)
if not pb:
return None
pb = (None,)[0]
width = pb.get_width()
height = pb.get_height()
color_depth = pb.get_bits_per_sample()
format_ = loader.get_format()
mime_types = format_.get_mime_types()
if not mime_types or mime_types[0]:
pass
mime_type = ''
try:
return cls(open(path, 'rb'), mime_type, width, height, color_depth)
except EnvironmentError:
return None
from_path = classmethod(from_path)